using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace One_Crappy_RPG
{
    class Camera
    {
        public Vector2 Position = Vector2.Zero;

        public Matrix CameraTransform
        {
            get
            {
                return Matrix.CreateTranslation(new Vector3(-Position, 0.0f));
            }
        }

        public Camera()
        {
        }

        public void Update(Hero target, TileMap map, ScreenManager screenManager)
        {
            Position.X = target.MapPosition.X - (screenManager.GraphicsDevice.Viewport.Width / 2);
            Position.Y = target.MapPosition.Y - (screenManager.GraphicsDevice.Viewport.Height / 2);

            //Clamp it
            if (Position.X < 0)
            {
                Position.X = 0;
            }

            if (Position.Y < 0)
            {
                Position.Y = 0;
            }

            if (Position.X + screenManager.GraphicsDevice.Viewport.Width >
                map.Layers[0].Width * TileMap.TileSize)
            {
                Position.X = map.Layers[0].Width * TileMap.TileSize -
                    screenManager.GraphicsDevice.Viewport.Width;
            }

            if (Position.Y + screenManager.GraphicsDevice.Viewport.Height >
                map.Layers[0].Height * TileMap.TileSize)
            {
                Position.Y = map.Layers[0].Height * TileMap.TileSize -
                    screenManager.GraphicsDevice.Viewport.Height;
            }
        }
    }
}
